clear all
set more off

use  "../data/decile_year_month_data",replace


collapse (sum) ct sr_val_tran chinese100* hispanic100* indian100* russian100* korean100* japanese100* american100* european100*, by(monthdate)

*generate adjusted FHTV/FHTC percents based on the three-step imputation algorithm for all ethnicities
foreach r in hispanic indian russian korean japanese european chinese{
gen `r'_cashvalall_percent = max((`r'100_cashval_tran - american100_cashval/american100_val*`r'100_val)*(american100_val/(american100_val - american100_cashval))/sr_*100,0.01)
gen `r'_cashctall_percent = max((`r'100cash - american100cash/american100*`r'100)*(american100/(american100 - american100cash))/ct*100,0.01)
}

tsset monthdate
rename monthdate month

*create values plot
twoway (tsline chinese_cashvalall_percent, lwidth(thick)) (tsline hispanic_cashvalall_percent) (tsline indian_cashvalall_percent) (tsline russian_cashvalall_percent) ///
(tsline korean_cashvalall_percent) (tsline japanese_cashvalall_percent) (tsline european_cashvalall_percent) ///
, legend(order(1 "Chinese" 2 "Hispanic" 3 "Indian" 4 "Russian" 5 "Korean" 6 "Japanese" 7 "European") rows(3)) ///
graphregion(color(white)) bgcolor(white) xlabel(492(24)647) ttitle("")
graph export "../results/figure1a.png", replace


*create count plot
twoway (tsline chinese_cashctall_percent , lwidth(thick)) (tsline hispanic_cashctall_percent ) (tsline indian_cashctall_percent ) (tsline russian_cashctall_percent ) ///
(tsline korean_cashctall_percent ) (tsline japanese_cashctall_percent )  (tsline european_cashctall_percent ) ///
, legend(order(1 "Chinese" 2 "Hispanic" 3 "Indian" 4 "Russian" 5 "Korean" 6 "Japanese" 7 "European") rows(3)) ///
graphregion(color(white)) bgcolor(white) xlabel(492(24)647) ttitle("")
graph export "../results/figure1b.png", replace

